<template>
  <div class="warpper">
    <van-sticky :offset-top="0">
      <van-search @search="handleSearch" v-model="keyword" autofocus background="#fff" shape="round" placeholder="请输入搜索关键词" />
    </van-sticky>
    <!-- 搜索end -->

    <div class="search">
      <div class="title">最近搜索</div>
      <div class="content">
        <div v-for="(item, index) in searchLatest" :key="index">
          <van-tag color="#ccc" type="primary">搜索</van-tag>
        </div>
      </div>
    </div>

    <div class="line"></div>

    <div class="search">
      <div class="title">热门搜索</div>
      <div class="content">
        <div v-for="(item, index) in searchLatest" :key="index">
          <van-tag color="#ccc" type="primary">搜索</van-tag>
        </div>
      </div>
    </div>

    <div class="grid">
      <div class="grid-item" v-for="(item, index) in recommend" :key="index">
        <img :src="'https://picsum.photos/200/300?' + index" alt="">
        <div class="title">
          Title
        </div>
        <div class="row">
          <div class="price">¥12</div>
          <div class="disprice">¥18</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'search',
  data() {
    return {
      searchLatest: new Array(10).fill(''),
      recommend: new Array(10).fill(''),
      keyword: ''
    }
  },
  methods: {
    handleSearch (val) {
      console.log(val);
      this.$toast.success(val)
    }
  }
}
</script>

<style lang="scss" scoped>
.warpper {
  background-color: #F8F8F8;
  padding: 5px;
}

.line {
  margin-top: 10px;
  margin-bottom: 10px;
  height: 0px;
  border-bottom: 1px solid #333;
}

.search {
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 20px;

  .content {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 0 10px;
    box-sizing: border-box;
  }

}

.price {
  color: chocolate;
  font-size: 16px;
  font-weight: bold;
}

.disprice {
  font-size: 14px;
  color: #CCC;
  text-decoration: line-through;
}

.grid {
  margin-top: 30px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;

  .grid-item {
    display: flex;
    background: #FFF;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    padding: 5px;
    gap: 3px;

    .title {
      font-size: 16px;
    }

    .row {
      display: flex;
    }



    >img {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
import { search } from 'core-js/fn/symbol';
